import 'package:flutter/material.dart';
import 'package:learningoncloud/zyf/Account/account.dart';

class Index extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '网易云课堂',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: '网易云课堂'),
      routes: {
        //'/Citys': (context) => CitysWidget(),
      },
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  int _selectedIndex = 0;

  //final _widgetItems = [HotWidget(), MoviesWidget(), MineWidget()];
  final _widgetItems = [MyAccount()];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _widgetItems[_selectedIndex],
      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.person), title: Text('账号')),
          BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('首页')),
          BottomNavigationBarItem(icon: Icon(Icons.apps), title: Text('分类')),
          BottomNavigationBarItem(icon: Icon(Icons.laptop_chromebook), title: Text('我的学习'))
        ],//BottomNavigationBarItem 的 icon 用的是 Icon Widget实现的，这里是随便找的图标，先实现功能，后续在改成和 豆瓣电影 的一样
        currentIndex: 0,//默认选中的 index
        fixedColor: Colors.grey, //选中时颜色变为黑色
        type: BottomNavigationBarType.fixed,//类型为 fixed
        onTap: _onItemTapped,
      ),
    );
  }

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;//刷新界面
    });
  }
}
